//package com.shanghaionstar.nav.manager;
//
//import android.content.Intent;
//import android.os.Message;
//
//import com.amap.api.maps2d.AMap;
//import com.amap.api.maps2d.UiSettings;
//import com.amap.api.services.core.ServiceSettings;
//import com.onstar.cn.common.log.LogManager;
//import com.onstar.cn.common.util.Constants;
//import com.onstar.cn.common.util.DeviceUtil;
//import com.onstar.cn.map.MapContainer;
//import com.onstar.cn.map.MapContainerImpl;
//import com.onstar.cn.map.OMapActivity;
//import com.onstar.cn.map.common.DriveSegmentInfo;
//import com.onstar.cn.map.common.LocationType;
//import com.onstar.cn.map.common.MapException;
//import com.onstar.cn.map.common.PoiItemInfo;
//import com.onstar.cn.map.core.OGeoPoint;
//import com.onstar.cn.map.core.impl.OGeoPointImpl;
//import com.onstar.cn.map.listener.ORouteHandlerListener;
//import com.shanghaionstar.nav.NavActivity;
//import com.shanghaionstar.utils.MapHandler;
//
//import java.util.List;
//
///**
// * Created by Rengui Lu on 2016/7/12.
// */
//public class RouterHandler{
//    private long caculateRoute = -1;
//    private LogManager logger;
//    protected AMap mMapView;
//
//    public MapContainer getmMapContainer() {
//        return mMapContainer;
//    }
//
//    public void setmMapContainer(MapContainer mMapContainer) {
//        this.mMapContainer = mMapContainer;
//    }
//
//    protected MapContainer mMapContainer;
//
//    public RouterHandler(OMapActivity oMapActivtiy, AMap mapView) {
//        this.mMapView = mapView;
//        UiSettings setting = this.mMapView.getUiSettings();
//        setting.setZoomControlsEnabled(false);
//        mMapContainer = new MapContainerImpl(oMapActivtiy, this.mMapView, null);
//        setLanguage(mapView);
//        init();
//    }
//
//    public void setTraffic(boolean isOpen) {
//        mMapView.setTrafficEnabled(isOpen);
//        mMapView.invalidate();
//    }
//
//    private void setLanguage(AMap mapView) {
//        if (DeviceUtil.isChineseLanguage()) {
//            mapView.setMapLanguage(AMap.CHINESE);
//            ServiceSettings.getInstance().setLanguage(ServiceSettings.CHINESE);
//        } else {
//            mapView.setMapLanguage(AMap.ENGLISH);
//            ServiceSettings.getInstance().setLanguage(ServiceSettings.ENGLISH);
//        }
//    }
//
////    @Override
////    public void init() {
////        logger = LogManager.getInstance();
////        if (routeListener != null) {
////            mMapContainer.registerMapRouteListener(routeListener);
////        }
////        setTraffic(true);
////    }
//
//    public void showRoute() {
//        mMapContainer.showRoute();
//    }
//
//    private OnRouteCalListener onRouteCalListener;
//
//    public void seOnRouteCalListener(OnRouteCalListener onRouteCalListener) {
//        this.onRouteCalListener = onRouteCalListener;
//    }
//
//    public interface OnRouteCalListener {
//        void onRouteComplete();
//
//        void onRouteError();
//    }
//
//    /**
//     * @param mapLevel    拉伸水平
//     * @param poiItemInfo 点信息
//     *                    根据尺度水和中心点初始化地图
//     */
//    public void initMapView(int mapLevel, PoiItemInfo poiItemInfo) {
//        logger.d("Method initMapView(int map_level, String cityName,oiItemInfo poiItemInfo)");
//        OGeoPoint center = new OGeoPointImpl(poiItemInfo.getLatitude(), poiItemInfo.getLongitude());
//        mMapContainer.initMapView(mapLevel, center);
//    }
//
//
//    /**
//     * @Title: caculateRoute @Description: 计算路径 @param @param
//     * routeStartPoiItemInfo @param @param routeEndPoiItemInfo
//     * 设定文件 @return void 返回类型 @throws
//     */
//    public void caculateRoute(PoiItemInfo routeStartPoiItemInfo, PoiItemInfo routeEndPoiItemInfo) {
//        caculateRoute = mMapContainer.caculateRoute(routeStartPoiItemInfo, routeEndPoiItemInfo, "小时", " 分钟");
//    }
//
//    private ORouteHandlerListener routeListener = new ORouteHandlerListener() {
//
//        @Override
//        public void OnCalculateTempRoute(long id, PoiItemInfo routeStartPoiItemInfo, PoiItemInfo routeEndPoiItemInfo) {
////            logger.d("OnCalculateTempRoute():id=" + id + "  routeStartPoiItemInfo=" + routeStartPoiItemInfo.getTitle()
////                    + "  routeEndPoiItemInfo=" + routeEndPoiItemInfo.getTitle());
////            setTempRouteStartPoiItemInfo(routeStartPoiItemInfo);
////            setTempRouteEndPoiItemInfo(routeEndPoiItemInfo);
////            caculateTempRoute(routeStartPoiItemInfo, routeEndPoiItemInfo);
//        }
//
//        @Override
//        public void OnRouteComplete(long id) {
////            String type = calculateRouteTypeMap.remove(String.valueOf(id));
////            PoiLocationInfoInstance.getInstance().setRouteDistance(mMapContainer.getRouteDistance());
////            PoiLocationInfoInstance.getInstance().setRouteTime(mMapContainer.getRouteTime());
////            logger.d("OnRouteComplete():type=" + type + " id=" + id + "   routeDistance=" + mMapContainer.getRouteDistance()
////                    + "  routeTime=" + mMapContainer.getRouteTime());
////            if (type.equalsIgnoreCase(CALCULATE_ROUTE_TEMP)) {
////                clearTempRoutePoints();
////                clearRouteOverlay();
////                mMapContainer.showTempRoute(false);
////                Message msg = Message.obtain();
////                msg.what = Constants.UPDATE_ROUTE_PROGRESSBAR;
////                Bundle bundle = new Bundle();
////                bundle.putBoolean(Constants.ROUTE_PROGREEBAR_SHOWING, false);
////                msg.setData(bundle);
////                PoiLocationInfoInstance.getInstance().getCommonHandler().sendMessage(msg);
////                PoiLocationInfoInstance.getInstance().getCommonHandler().sendEmptyMessage(Constants.POI_ACTIVITY_SHOW_TEMP_ROUTE_TIPS);
////
////                BusinessUtil.sendReportByClickType(mainTabActivity,
////                        FunctionNameFindId.ClickMapToViewRoute.getStringValue());
////
////            } else {
////                PoiLocationInfoInstance.getInstance().setRouteSearchStatus(RouteSearchStatusType.Completed);
////                List<DriveSegmentInfo> driveSegmentInfoList = mMapContainer.getDriveSegmentResultList();
////                PoiLocationInfoInstance.getInstance().setDriveSegmentInfoList(driveSegmentInfoList);
////                PoiLocationInfoInstance.getInstance().getCommonHandler().sendEmptyMessage(Constants.ROUTE_SEARCH_SUCCESS);
////            }
////            PoiLocationInfoInstance.getInstance().setRouteSearchStatus(RouteSearchStatusType.Completed);
//            List<DriveSegmentInfo> driveSegmentInfoList = mMapContainer.getDriveSegmentResultList();
//            if (mActivity instanceof NavActivity) {
//                ((NavActivity) mActivity).getMapHandler().setSegmentInfoList(driveSegmentInfoList);
//            }
//            onRouteCalListener.onRouteComplete();
////            PoiLocationInfoInstance.getInstance().setDriveSegmentInfoList(driveSegmentInfoList);
////            sendBroadcast();
////            PoiLocationInfoInstance.getInstance().getCommonHandler().sendEmptyMessage(Constants.ROUTE_SEARCH_SUCCESS);
//        }
//
//        @Override
//        public void OnRouteErrors(long id, MapException mapException) {
//            logger.e("OnRouteErrors():id=" + id + "   errorMessage=" + mapException.getErrorString());
//            logger.e(mapException.getErrorString(), mapException.getExp());
////            PoiLocationInfoInstance.getInstance().setRouteSearchStatus(RouteSearchStatusType.Completed);
////            logger.d("OnRouteErrors():id=" + id + " generate route failed: getRouteSearchStatus="
////                    + PoiLocationInfoInstance.getInstance().getRouteSearchStatus());
//            //Handler h = navFragments.getCommonHandler();
//            //Message msg = h.obtainMessage();
//            Message msg = Message.obtain();
//            msg.what = Constants.SEARCH_FAIL;
//            msg.obj = mapException.getErrorString();
//            msg.sendToTarget();
//            onRouteCalListener.onRouteError();
//        }
//
//        @Override
//        public void OnRouteStartPoint(LocationType type) {
//            logger.e("OnRouteStartPoint():LocationType=" + type.name());
//            clearRouteOverlay();
////            routeStartLocationType = type.getValue();
//        }
//
//        @Override
//        public void OnRouteEndPoint(LocationType type) {
//            logger.e("OnRouteStartPoint():LocationType=" + type.name());
////            routeEndLocationType = type.getValue();
//        }
//
//    };
//
//    private void sendBroadcast() {
//        Intent intent = new Intent();
//        intent.setAction("SearchRouteSuccess");
//        intent.putExtra("SEARCHROUTE", "success");
//        mActivity.sendBroadcast(intent);
//    }
//
////
//
//    public void clearRouteOverlay() {
//        mMapContainer.clearRouteOverlay();
//    }
//
//}
